<?php

namespace App\Http\Middleware;

use App\Api\Models\SystemConfigModel;
use App\Helper\DBRSAUtil;
use App\Models\AdminModel;
use App\V3\Api\Controllers\AdminController;
use Closure;
use Illuminate\Http\Request;
use Jenssegers\Agent\Agent;

class IsUpkeep
{
    /**
     * Handle an incoming request.
     *
     * @param \Illuminate\Http\Request $request
     * @param \Closure(\Illuminate\Http\Request): (\Illuminate\Http\Response|\Illuminate\Http\RedirectResponse) $next
     * @return \Illuminate\Http\JsonResponse
     */
    public function handle(Request $request, Closure $next)
    {
        $info = SystemConfigModel::where('key_value', 'is_upkeep')->first();

        $tokenInfo = explode(' ', $request->header('token'));
        /* $loginType = 0;
         $agent = new Agent();
         if ($agent->isMobile()) {
             // 移动端
             $loginType = 1;
         } else if ($agent->isDesktop()) {
             // 电脑端
             $loginType = 0;
         }*/
        if ($tokenInfo[0] != [1, 19285, 19286, 19287, 9604]) {
            //if ($loginType) {
                if ($info['value']) {
                    return response()->json([
                        'code' => 8,
                        'msg' => '系统维护中，预计所需时间2个小时。。。。。。',
                        'data' => ''
                    ]);
                }
            //}
        }
        return $next($request);
    }
}
